 

#!/usr/bin/env bash

TABLENAME=symbols
SYMBOL_DB_FILE="symbols"
STRING_SYMBOL_FILE="func.list"

CONFUSE_FILE="$PROJECT_DIR/"

#HEAD_FILE="$PROJECT_DIR/$PROJECT_NAME/codeObfuscation.h"
HEAD_FILE="$PROJECT_DIR/codeObfuscation.h"
echo "路径 ${HEAD_FILE}"
export LC_CTYPE=C

#ramdomString()
#{
#openssl rand -base64 64 |tr -cd '[a-zA-Z0-9]' |head -c 16
#}
#
#ram=`ramdomString`
#echo -e "随机字符串 -->${ram}\n\n"
#
#exit 1

grep -h -r -I "^[-+]" $CONFUSE_FILE --include '*.[mh]' |sed "s/[+-]//g"|sed "s/[();,: *\^\/\{]/ /g"|sed "s/[ ]*</</"| sed "/^[ ]*IBAction/d"|awk '{split($0,b," "); print b[2]; }'| sort|uniq |sed "/^$/d"|sed -n "/^dd_/p">$STRING_SYMBOL_FILE

#维护数据库方便日后作排重
createTable()
{
echo "create table $TABLENAME(src text, des text);" | sqlite3 $SYMBOL_DB_FILE
}

insertValue()
{
echo "insert into $TABLENAME values('$1' ,'$2');" | sqlite3 $SYMBOL_DB_FILE
}

query()
{
echo "select * from $TABLENAME where src='$1';" | sqlite3 $SYMBOL_DB_FILE
}

ramdomString()
{
openssl rand -base64 64 | tr -cd 'a-zaA-Z' |head -c 4
}

rm -f $SYMBOL_DB_FILE
rm -f $HEAD_FILE
createTable

touch $HEAD_FILE
echo '#ifndef codeObfuscation_h \n#define codeObfuscation_h' >> $HEAD_FILE
echo "//confuse string at `date`" >> $HEAD_FILE
cat "$STRING_SYMBOL_FILE" | while read -ra line; do
if [[ ! -z "$line" ]]; then
ramdom="newdd_actionFor"`ramdomString`${line:4:10}`ramdomString`
#指定开头为yy_actionFor，中间/结尾截取4个字符，以及选取原字符的第四个起，长度为10的字符
#ramdom=`ramdomString`
echo $line $ramdom
insertValue $line $ramdom
echo "#define $line $ramdom" >> $HEAD_FILE
fi
done
echo "#endif" >> $HEAD_FILE


sqlite3 $SYMBOL_DB_FILE .dump
